package com.ahrhyj.system.net;

import com.ahrhyj.common.utils.http.HttpUtils;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
public class SendSmsApi {

    @Value("${sms.enabled}")
    private String enabled;
    @Value("${sms.userid}")
    private String userid;
    @Value("${sms.account}")
    private String account;
    @Value("${sms.password}")
    private String password;


    public SendSmsResult doSms(String receiveUser, String smsContent) {
        if (StringUtils.isNotBlank(enabled) && enabled.equals("false")){
            SendSmsResult sendSmsResult = new SendSmsResult();
            sendSmsResult.setReturnStatus("Success");
            sendSmsResult.setMessage("接口关闭");
            return sendSmsResult;
        }
        if (StringUtils.isNotBlank(receiveUser) && StringUtils.isNotBlank(smsContent)) {
            try {
                String url = "http://120.27.148.186:8088/sms.aspx";
                String params = "action=send&rt=json&userid=" + userid + "&account=" + account + "&password=" + password + "&mobile=" + receiveUser + "&content=" + smsContent + "&sendTime=&extno=";
                String result = HttpUtils.sendGet(url, params);
                if (StringUtils.isNotBlank(result)){
                    return JSONObject.parseObject(result, SendSmsResult.class);
                }
            } catch (Exception ex) {

            }
        }
        return null;
    }

}
